<%@ page language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
    <base href="<%=basePath%>">

    <title>${sessionScope.topicName} - ${tag}</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

    <%@include file="im.jsp" %>
    <link rel="stylesheet" href="css/pagination.css"/>
    <link rel="stylesheet" href="css/subPage.css"/>
    <script type="text/javascript" src="js/jquery.pagination.js"></script>
    <script type="text/javascript">
        $(function () {


            var initPagination = function () {
                num_entries = $("#hiddenresult div.result").length;
                // 创建分页
                page = 10; //!!!!!!每页个数！！！！！！
                $("#Pagination").pagination(num_entries, {
                    num_edge_entries: 2, //边缘页数
                    num_display_entries: 6, //主体页数
                    callback: pageselectCallback,
                    items_per_page: page, //每页显示1项
                    prev_text: "前一页",
                    next_text: "后一页"
                });
            }();

            function pageselectCallback(page_index, jq) {
                //alert("IIIII");
                var max_elem = Math.min((page_index + 1) * page, num_entries);
                $("#Searchresult").empty();
                for (var i = page_index * page; i < max_elem; i++) {
                    $("#Searchresult").append(
                            $("#hiddenresult div.result:eq(" + i + ")").clone());
                }
                ajaxFocus();
                return false;
            }

            function ajaxFocus() {
                $(".favorite").click(function () {
                    var aID = $(this).attr("id");
                    var articleObject = $(this);
                    if ($(this).attr("src") == "images/selected.png") {
                        $.ajax({
                            type: "POST",
                            url: "ajax.jsp",
                            data: "articleID=" + aID + "&operation=delete",
                            beforeSend: function () {
                                //alert("数据处理中...");
                            },
                            success: function (msg) {
                                //alert(msg);
                                articleObject.attr("src", "images/unselected.png");
                                articleObject.attr("alt", "我关注");
                            },
                            error: function (xhr, type, exception) {
                                alert("对不起，出错了！");
                            }
                        });
                    } else {

                        $.ajax({
                            type: "POST",
                            url: "ajax.jsp",
                            data: "articleID=" + aID + "&operation=add",
                            beforeSend: function () {
                                //alert("数据处理中...");
                            },
                            success: function (msg) {
                                //alert(msg);
                                articleObject.attr("src", "images/selected.png");
                                articleObject.attr("alt", "取消\"关注\"");
                            },
                            error: function (xhr, type, exception) {
                                alert("对不起，出错了！");
                            }
                        });
                    }
                });
            }

        });
    </script>

</head>

<body>
<logic:equal name="user" value="administrator">
    <div class="container">

        <%@include file="top.jsp" %>

        <div class="row">
            <%@include file="left.jsp" %>


            <div class="col-md-9">
                <div style="padding-left:35px">
                    <div style="font-weight: bolder;font-size: larger;">
                        话题：<bean:write name="cluster" property="name"></bean:write>
                        <br>
                        热度：<bean:write name="cluster" property="count"></bean:write>
                    </div>
                    <div class="btn-group pull-right" data-toggle="buttons">
                        <label class="btn btn-default" onclick="location.href='placeAnalyzeAction.do?method=getHeadMap&clusterID=${cluster.id}'">
                            <input type="radio" name="options" id="option1">
                            地域分析
                        </label>
                        <label class="btn btn-default" onclick="location.href='timelineAction.do?method=showTimeline&clusterID=${cluster.id}'">
                            <input type="radio" name="options" id="option2">                            传播分析
                        </label>
                    </div>

                    <hr/>
                    <div class="titlebox">
                        <div class="title">
                            <b><%=request.getAttribute("tag")%>
                            </b>
                        </div>
                    </div>
                    <div id="Searchresult">
                        分页初始化完成后这里的内容会被替换。
                    </div>
                    <div id="hiddenresult" style="display: none;">
                        <!-- 标题title -->
                        <logic:present name="result" scope="request">
                            <logic:iterate id="newest" name="result">
                                <!-- 标题title -->
                                <div class="result">
                                    <h4>
                                        <logic:equal value="true" name="newest" property="star">
                                            <img id="${newest.id }" class="favorite"
                                                 src="images/selected.png" alt="已关注该新闻" width="15"
                                                 height="14"/>
                                        </logic:equal>
                                        <logic:equal value="false" name="newest" property="star">
                                            <img id="${newest.id }" class="favorite"
                                                 src="images/unselected.png" alt="关注该新闻" width="15"
                                                 height="14"/>
                                        </logic:equal>
                                        <!--输出标题和链接-->
                                        <html:link paramId="link" page="/logAction.do"
                                                   paramName="newest" paramProperty="link" target="_blank">
                                            <logic:notEqual name="newest" property="title" value="">
                                                <bean:write name="newest" property="title" filter="true"/>
                                            </logic:notEqual>
                                            <logic:equal name="newest" property="title" value="">暂无标题</logic:equal>
                                        </html:link>
                                            <%--</html:link>--%>
                                        <!-- 输出站点 -->
                                        [
                                        <logic:notEqual name="newest" property="site" value="">
                                            <bean:write name="newest" property="site"></bean:write>
                                        </logic:notEqual>
                                        ]
                                        <!-- 输出时间 -->
                                        <logic:notEqual name="newest" property="time" value="">
                                            [<bean:write name="newest"
                                                         property="time"/>]
                                        </logic:notEqual>

                                    </h4>
                                    <!-- 输出摘要 -->
                                    <p>
                                        <bean:write name="newest" property="abstext" filter="true"/>
                                    </p>
                                </div>
                            </logic:iterate>
                        </logic:present>
                    </div>
                    <div id="Pagination" class="pagination">
                        <!-- 这里显示分页 -->
                    </div>


                </div>
                <!--					<div class="right_right">-->

                <!--					</div>-->
            </div>
        </div>
        <!--end of right-->
        <div class="footer">
            <%@ include file="foot.jsp" %>
        </div>
    </div>
</logic:equal>
<logic:empty name="user">
    Access Rejected! Error 404
</logic:empty>
</body>
</html>
